<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ChangeCourse_Page</title>
<script src="../jquery-3.5.1.js"></script>
<script src="../jquery.cookie.js"></script>
<script>var userid = sessionStorage.getItem('testKey');
console.log(userid);
if(userid == null || userid == "")
	{
	window.location = "/login.html";
	}
</script>
<style>
body
{
font-size:75%;
font-family:verdana,arial,'sans serif';
background-repeat:repeat-x;
background-color:#FFFFF0;
}

h1 {font-size:200%;}
h2 {font-size:140%;}
h3 {font-size:110%;}

th {background-color:#ADD8E6;}


ol {list-style:upper-roman;}

ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #333;
}

li {
    float: left;
}

li a {
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

li a:hover {
    background-color: #111;
}
.active{

background-color: #bfbfbf;
}
.foot {
	position: fixed;
	bottom: 5px;
	text-align: center;
	padding: 10px;
	border-radius: 6px;
	background-image: linear-gradient(to bottom right, #ffb21a, #ffdd99);
}
</style>

<script type="text/javascript">
var url = decodeURI(window.location.href);

var argsIndex = url .split("?courseid=");
var cid = argsIndex[1];
window.onload =function(){
	 $.ajax({
		 
	        type: 'GET',
	        url: "/courseTeachingById/"+cid,
	        contentType: "application/json;cherset=utf-8",
	        dataType: "json",
	        success: function (data){
	               $("#cid").val(data.course.id);
	               $("#id").val(data.id);
	               $("#name").val(data.course.name);
	               $("#semester").val(data.semester);
	               $("#year").val(data.year);
	               $("#tid").val(data.teacher.tid);
	              console.log(data);
	              } ,
	        error: function (data) {
	            alert("error:" + JSON.stringify(data));}
	    });
	
}

function editCourse(){
	var sid= $("#cid").val();
	 $.ajax({
	        url:'/courseTeaching/' + cid ,
	        data:$('#edit').serialize(),
	        type:'PUT',
	        
	        success:function(data){
	        
	        if(data == "success")
	        	javascript:history.back(-1);
	        },
	        error:function(){
	        	
		       alert("error!");
	        },
})
}
</script>

</head>
<body>
<ul><!--导航栏 -->
  <li><a href="AdminPage.html">主页</a></li>
  <li><a href="TchModify.html">老师修改页面</a></li>
  <li><a href="StuModify.html">学生修改页面</a></li>
  <li><a href="CoursesModify.html">课程修改页面</a></li>
  <li><a class="active" href="CourseTchModify.html">教师开课修改页面</a></li>
  <li><a href="AllScore.html">分数查询页面</a></li>
</ul>
<br/>
	<em>Rewrite information down here</em>
	
	<form method="post" id="edit">
		<table>
		<tr>
				<td>教师编号</td>
				<td><input type="text" name="teacher.tid" id="tid" readonly/></td>
			</tr>
			<tr>
				<td>开课编号</td>
				<td><input type="text" name="id" id="id" readonly/></td>
			</tr>
			<tr>
				<td>课程编号</td>
				<td><input type="text" name="course.id" id="cid" readonly/></td>
			</tr>
			<tr>
				<td>课程名称</td>
				<td><input type="text" name="name" id="name" readonly/></td>
			</tr>
			<tr>
				<td>开课学期</td>
				<td>
				<input type="text" name="semester" id="semester"/>
				</td>
			</tr>
			<tr>
				<td>开课学年</td>
				<td><input type="text" name="year" id="year" /></td>
			</tr>
			
			<tr>
				<td><button type="button" onclick="editCourse()">修改</button></td>
			</tr>
		</table>
	</form>	
</body>
</html>